package a.a.a;

import net.roseboy.classfinal.JarDecryptor;
import net.roseboy.classfinal.util.EncryptUtils;
import net.roseboy.classfinal.util.IoUtils;
import net.roseboy.classfinal.util.SysUtils;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;

public class D {
    public static void main(String[] args) {
        IoUtils.writeFile(new File("D://licence.sunray"), buildLicenceSunray("2022-01-01","2022-12-31","2022-12-31"));
        C.init();
        Map<String,String> result=getConfigInfo("D://");
        System.out.println(result);
    }
    public static String fileName="licence.sunray";
    public static Map<String,String> getConfigInfo(String projectPath){
        Map<String,String> config=new LinkedHashMap<>();
        byte[] bytes = JarDecryptor.getInstance().getBytes(projectPath, "licence.sunray");
        byte[] bs=B.d(bytes,fileName.getBytes(StandardCharsets.UTF_8));
        String[] strings=new String(bs).split("\n");
        for (String string : strings) {
            String[] split = string.split("=");
            config.put(split[0], split[1]);
        }
        return config;
    }
    public static byte[] buildLicenceSunray(String startTime,String endTime,String leaveTime){
        String content="";
        content+="startTime="+startTime+"\n";
        content+="endTime="+endTime+"\n";
        content+="leaveTime="+leaveTime+"\n";
        content+="marchinCode="+new String(SysUtils.makeMarchinCode())+"\n";
        content+="hash="+ bytesToHex(EncryptUtils.md5byte(content.getBytes()));

        return B.e(content.getBytes(),fileName.getBytes(StandardCharsets.UTF_8));
    }
    public static String bytesToHex(byte[] bytes) {
        StringBuilder result = new StringBuilder();
        for (byte b : bytes) {
            result.append(String.format("%02x", b));
        }
        return result.toString();
    }
}
